package edu.neu.agv_backend.service;

import edu.neu.agv_backend.dto.*;
import edu.neu.agv_backend.remote.RemoteClient;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Service;

@Service
public class TaskService {

    private final RemoteClient client;

    public TaskService(RemoteClient client) {
        this.client = client;
    }

    public TableDataInfo<AgvTaskDto> listTask(String query) {
        return client.get("/agv/task/list" + query, TableDataInfo.class).getBody();
    }

    public AjaxResult<AgvTaskDto> getTask(Long id) {
        return client.get("/agv/task/" + id, AjaxResult.class).getBody();
    }

    public AjaxResult<Void> addTask(AgvTaskDto dto) {
        return client.post("/agv/task", dto, AjaxResult.class).getBody();
    }

    public AjaxResult<Void> updateTask(AgvTaskDto dto) {
        return client.put("/agv/task", dto, AjaxResult.class).getBody();
    }

    public AjaxResult<Void> delTask(Long id) {
        return client.delete("/agv/task/" + id, AjaxResult.class).getBody();
    }

    public AjaxResult<Void> startTask(Long id) {
        return client.post("/agv/task/start/" + id, null, AjaxResult.class).getBody();
    }

    public AjaxResult<Void> endTask(Long id, boolean isAbort) {
        String query = "?isAbort=" + isAbort;
        return client.post("/agv/task/end/" + id + query, null, AjaxResult.class).getBody();
    }

    public AjaxResult<Void> preUpload(Long id) {
        return client.get("/agv/task/preupload/" + id, AjaxResult.class).getBody();
    }

    public AjaxResult<Void> upload(Long id) {
        return client.post("/agv/task/upload/" + id, null, AjaxResult.class).getBody();
    }
} 